#include "getdata.h"

GetData::GetData()
{

}

QVariantList GetData::getVariant_Device(int deviceid){

    if(0==deviceid)
    {
        return sqldate->Query("select * from device_view");
    }
    else
    {
        return sqldate->Query("select * from device_view where deviceId="+QString::number(deviceid));
    }
}

QVariantList GetData::getVariant_Code(int codeid){

    if(0==codeid)
    {
        return sqldate->Query("select * from code_view");
    }
    else
    {
        return sqldate->Query("select * from code_view where codeId="+QString::number(codeid));
    }
}



QVariantList GetData::getVariant_Server(int serverid){

    if(0==serverid)
    {
        return sqldate->Query("select * from server_view");
    }
    else
    {
        return sqldate->Query("select * from server_view where serverId="+QString::number(serverid));
    }
}
QVariantList GetData::getVariant_ServerSendTask(int serverid){

    if(0==serverid)
    {
        return sqldate->Query("select * from sendtask_view order by msgQN asc");
    }
    else
    {
        return sqldate->Query("select * from sendtask_view where serverId="+QString::number(serverid));
    }
}


QVariantList GetData::getVariant_ServerProtocol(QString protocolId)
{
    if(QString("00000000000000000000000000000000")==protocolId)
    {
        return sqldate->Query("select * from serverprotocol_view");
    }
    else
    {
        return sqldate->Query("select * from serverprotocol_view where protocolId='"+protocolId+"'");
    }
}




QVariantList GetData::getVariant_DeviceProtocolGroup()
{
    return sqldate->Query("select DISTINCT protocolGroup from deviceprotocol_view");
}

QVariantList GetData::getVariant_DeviceProtocolByGroup(QString group)
{
    //qDebug()<<group;
    return sqldate->Query("select protocolId, protocolName, protocolText from deviceprotocol_view where protocolGroup='"+group+"'");
}


QVariantList GetData::getVariant_DeviceProtocol(QString protocolId)
{
    if(QString("00000000000000000000000000000000")==protocolId)
    {
        return sqldate->Query("select * from deviceprotocol_view");
    }
    else
    {
        return sqldate->Query("select * from deviceprotocol_view where protocolId='"+protocolId+"'");
    }
}






//QString GetData::getJSON_Device(int deviceid){return JsonHelper::getJson(getVariant_Device(deviceid));}
//QString GetData::getJSON_Devices(){return JsonHelper::getJson(getVariant_Device());}

//QString GetData::getJSON_Server(int serverid){return JsonHelper::getJson(getVariant_Server(serverid));}
//QString GetData::getJSON_Servers(){return JsonHelper::getJson(getVariant_Server());}

